package com.hang.mapstruct;

import com.hang.entity.Module;
import com.hang.model.dto.request.ModuleModelDTO;
import com.hang.model.vo.ModuleDetailVO;
import com.hang.model.vo.ModuleInfoVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

import java.util.LinkedList;
import java.util.List;

@Mapper(componentModel = "spring")
public interface ModuleMapStruct {
    Module ModuleModelDTOToModule(ModuleModelDTO moduleModelDTO);

    default List<ModuleInfoVO> moduleListToModuleInfoVOList(List<Module> moduleList){
        List<ModuleInfoVO> moduleInfoVOList = new LinkedList<>();
        moduleList.forEach(
                module -> {
                    moduleInfoVOList.add(moduleToModuleInfoVO(module));
                }
        );
        return moduleInfoVOList;
    }

    @Mapping(source = "moduleId",target = "moduleId")
    @Mapping(source = "moduleType",target = "moduleType",qualifiedByName = "typeFormatter")
    ModuleInfoVO moduleToModuleInfoVO(Module module);

    @Mapping(source = "moduleId",target = "moduleId")
    @Mapping(source = "moduleType",target = "moduleType",qualifiedByName = "typeFormatter")
    ModuleDetailVO moduleToModuleDetailVO(Module dbModule);

    @Named("typeFormatter")
    default String typeFormatter(Integer moduleType){
        if(moduleType == 1){
            return "基础模块";
        }else if(moduleType == 2){
            return "公共模块";
        }else if(moduleType == 3){
            return "应用模块";
        }else {
            return "其它模块";
        }
    }
}
